package com.socketeg.demo.controller;

import com.socketeg.demo.dto.SendObjectDTO;
import com.socketeg.demo.socket.Server;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;

@RestController
@RequestMapping("/sendMessage")
public class Message {

    @PostMapping
    public String sendMessage(@RequestBody SendObjectDTO sendObjectDTO) throws IOException {
        Server server = new Server();
        return server.pushMessageToClient(sendObjectDTO.getAddr(), sendObjectDTO.getMessage());
    }
}
